/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
//判断树中是否有字数和另一棵树一致  力扣572
class Solution4 {
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(root!=null){
            if(isSameTree(root,subRoot)){
                return true;
            }
            return isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot);
        }
        return false;
    }
    public boolean isSameTree(TreeNode a,TreeNode b){
        if(a==null&&b==null){
            return true;
        }else if(a==null||b==null){
            return false;
        }else{
            if(a.val!=b.val){
                return false;
            }else{
                return isSameTree(a.left,b.left)&&isSameTree(a.right,b.right);
            }
        }
    }
}